package com.zengdada.authority.utils.excel.export.title;


import com.zengdada.authority.utils.excel.export.style.MyCellStyle;
import com.zengdada.authority.utils.excel.export.style.MyCellStyleSize;

import java.util.ArrayList;
import java.util.Collection;

/**
 * @author 12614
 * @contact 1261438511@qq.com
 * @date 2020-05-25 23:32
 * @describe excel 行表头集合
 */
public class RowTableTitle extends ArrayList<CellTableTitle> {
    public final static int COMPACT_MODEL = 0, WIDE_MODEL = 1;
    private int maxHeight; // 自动调整行高
    private int minHeight = 1;
    private int avgHeight;
    private int allWidth;
    private int allHeight;
    private MyCellStyleSize cellSize;
    private MyCellStyle cellStyle;

    public MyCellStyleSize getCellSize() {
        return cellSize;
    }

    public RowTableTitle setCellSize(MyCellStyleSize cellSize) {
        this.cellSize = cellSize;
        return this;
    }

    public MyCellStyle getCellStyle() {
        return cellStyle;
    }

    public RowTableTitle setCellStyle(MyCellStyle cellStyle) {
        this.cellStyle = cellStyle;
        return this;
    }

    //            private int height;
//
//            public int getHeight() {
//                return height;
//            }


    public int getAvgHeight() {
        return avgHeight;
    }

    public int getMaxHeight() {
        return maxHeight;
    }

    public int getMinHeight() {
        return minHeight;
    }

    public int getAllWidth() {
        return allWidth;
    }

    public int getAllHeight() {
        return allHeight;
    }

    protected void calculation() {
        for (CellTableTitle cellTableTitle : this) {
            int height = cellTableTitle.getHeight();
            maxHeight = Math.max(maxHeight, height);
            minHeight = Math.min(minHeight, height);
            allWidth += cellTableTitle.getWidth();
            allHeight += height;
        }
        avgHeight = Math.round(((float) allHeight) / this.size());
    }

    @Override
    public boolean add(CellTableTitle tableTitle) {
        if (tableTitle == null) {
            throw new NullPointerException("对象不能为空");
        }
        return super.add(tableTitle);
    }

    @Override
    public void add(int index, CellTableTitle tableTitle) {
        if (tableTitle == null) {
            throw new NullPointerException("对象不能为空");
        }
        super.add(index, tableTitle);
    }

    @Override
    public boolean addAll(Collection<? extends CellTableTitle> c) {
        for (CellTableTitle tableTitle : c) {
            if (tableTitle == null) {
                throw new NullPointerException("对象不能为空");
            }
        }
        return super.addAll(c);
    }

    @Override
    public boolean addAll(int index, Collection<? extends CellTableTitle> c) {
        for (CellTableTitle tableTitle : c) {
            if (tableTitle == null) {
                throw new NullPointerException("对象不能为空");
            }
        }
        return super.addAll(index, c);
    }
}
